import { allAlarmDetails, allAlarmRead } from '@gis/lib/api';
import { dialog } from '@gis/lib/components/antd-dialog';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { h } from 'vue';
import { Button } from 'ant-design-vue';
import { openAlarmHandleDialog } from './alarm-handle.js';

export function openAlarmDetailsDialog(data, type = 'D0142_1') {
  // 是否阅读 0未读
  const { read_status } = data;
  if (read_status == 0) {
    allAlarmRead({ id: data.id });
  }
  const detailsFooter = {
    name: 'alarm-dev-details-footer',
    methods: {
      // turnEvent() {
      //   convertEvent({ id: data.id }).then((res) => {
      //     if (res) this.$emit('ok');
      //   });
      // },
      // eventDetails() {
      //   openEventDetailsDialog(data.event_id);
      // },
      warnHandle() {
        openAlarmHandleDialog(data).then((res) => {
          if (res) this.$emit('ok');
        });
      },
    },
    render() {
      return h('a-space', {}, [
        /*data.handle_status == 0 && !data.event_id
          ? h(Button, { type: 'primary', onClick: () => this.turnEvent() }, '指派')
          : null,*/
        data.handle_status == 0 ? h(Button, { type: 'primary', onClick: () => this.warnHandle() }, '处理') : null,
      ]);
      /*(
        <a-space>
          {/!*{data.is_handle == 1 && data.is_read == 1 ? (
            <a-button type="primary" onClick={this.read}>
              标记已读
            </a-button>
          ) : null}*!/}
          {data.handle_status == 0 && !data.event_id ? (
            <a-button type="primary" onClick={this.turnEvent}>
              指派
            </a-button>
          ) : null}
          {/!*{data.event_id ? (
            <a-button type="primary" onClick={this.eventDetails}>
              事件详情
            </a-button>
          ) : null}*!/}
          {data.handle_status == 0 ? (
            <a-button type="primary" onClick={this.warnHandle}>
              处理
            </a-button>
          ) : null}
        </a-space>
      );*/
    },
  };
  return new Promise(async (resolve) => {
    const contentEnum = {
      D0142_1: () => import('./people-detail.vue'),
      D0142_3: () => import('./house-detail.vue'),
      D0142_4: () => import('./dev-details.vue'),
      D0142_6: () => import('./push-details.vue'),
    };
    const details = await handleCommonRes(allAlarmDetails({ id: data.id }));
    dialog({
      content: contentEnum[type],
      contentProps: { details: details },
      dialogProps: {
        width: 'large',
        title: '预警详情',
        height: 'fixed',
        footer: detailsFooter,
        onOk: () => resolve(true),
        // afterClose: () => resolve(true),
      },
    });
  });
}
